package com.xphuong.newskios.util;

import java.util.ArrayList;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

import com.xphuong.model.News;
import com.xphuong.newskios.R;

public class Util {

	public static final String NEWSPAPER_ID = "newspaper_id";
	public static final String NEWSPAPER_TITLE = "newspaper_title";

	public static final String TOPIC_TITLE = "topic_title";
	public static final String TOPIC_LINK = "topic_link";

	public static final int LOAD_NEWS_TASK = 0;

	public static ArrayList<News> lstNews;

	public static String[] getTopicName(Context ctx, int newsId) {
		String[] topic = {};

		switch (newsId) {
		case 0:
			topic = ctx.getResources().getStringArray(R.array.dantri_cat_array);
			break;
		case 1:
			topic = ctx.getResources().getStringArray(
					R.array.vnexpress_cat_array);
			break;
		case 2:
			topic = ctx.getResources().getStringArray(
					R.array.vietnamnet_cat_array);
			break;
		case 3:
			topic = ctx.getResources()
					.getStringArray(R.array.ngoisao_cat_array);
			break;
		case 4:
			topic = ctx.getResources().getStringArray(R.array.yahoo_cat_array);
			break;
		case 5:
			topic = ctx.getResources().getStringArray(R.array.tiin_cat_array);
			break;
		case 6:
			topic = ctx.getResources().getStringArray(
					R.array.vietgiaitri_cat_array);
			break;
		case 7:
			topic = ctx.getResources().getStringArray(R.array.haivl_cat_array);
			break;
		case 8:
			topic = ctx.getResources().getStringArray(R.array.kenh14_cat_array);
			break;
		default:
			break;
		}

		return topic;
	}

	public static String[] getTopicLink(Context ctx, int newsId) {
		String[] topic = {};

		switch (newsId) {
		case 0:
			topic = ctx.getResources()
					.getStringArray(R.array.dantri_link_array);
			break;
		case 1:
			topic = ctx.getResources().getStringArray(
					R.array.vnexpress_link_array);
			break;
		case 2:
			topic = ctx.getResources().getStringArray(
					R.array.vietnamnet_link_array);
			break;
		case 3:
			topic = ctx.getResources().getStringArray(
					R.array.ngoisao_link_array);
			break;
		case 4:
			topic = ctx.getResources().getStringArray(R.array.yahoo_link_array);
			break;
		case 5:
			topic = ctx.getResources().getStringArray(R.array.tiin_link_array);
			break;
		case 6:
			topic = ctx.getResources().getStringArray(
					R.array.vietgiaitri_link_array);
			break;
		case 7:
			topic = ctx.getResources().getStringArray(R.array.haivl_link_array);
			break;
		case 8:
			topic = ctx.getResources()
					.getStringArray(R.array.kenh14_link_array);
			break;
		default:
			break;
		}

		return topic;
	}

	public static String getImage(String imageLink) {
		String content = "";
		if (imageLink != null && imageLink.length() > 0) {
			content += "<html><head><meta name='viewport' content='width=device-width'><title></title></head><body style='margin: 0px;' cz-shortcut-listen='true'><img style='-webkit-user-select: none' src='"
					+ imageLink + "'></body></html>";
		}
		return content;
	}

	public static boolean isNetworkAvaiable(Context ctx) {
		ConnectivityManager cm = (ConnectivityManager) ctx
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = cm.getActiveNetworkInfo();

		return (info != null);
	}
}
